package com.hiep.connect.client.view;

import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.datepicker.client.DateBox;
import com.hiep.connect.client.UiUtils;
import com.hiep.connect.client.presenter.EditProfilePresenter.EditProfileDisplay;
import com.hiep.connect.shared.MyUser;

public class EditProfileView extends Composite implements EditProfileDisplay {
	private Button saveButton;
	private Button cancelButton;
	private MyUser user;

	private Label titleLabel;
	private Label nameLabel;
	private Label dobLabel;
	private Label emailLabel;
	private TextBox nameBox;
	private TextBox emailBox;
	private TextBox dobBox;

	private Label passwordLabel;
	private PasswordTextBox passwordBox;

	public EditProfileView(MyUser user) {
		this.user = user;
		initGui();
	}

	private void initGui() {
		FlexTable flexTable = new FlexTable();
		flexTable.setCellSpacing(10);

		titleLabel = new HTML("<b>UPDATE PROFILE");
		nameLabel = new Label("Name");
		nameBox = new TextBox();
		emailLabel = new Label("Email Address");
		emailBox = new TextBox();
		dobLabel = new Label("Birthday");
		dobBox = new TextBox();
		passwordLabel = new Label("Password");
		passwordBox = new PasswordTextBox();

		nameBox.setText(user.getName());
		emailBox.setText(user.getEmail());
		passwordBox.setText(user.getPassword());

		saveButton = new Button("Save");
		cancelButton = new Button("Cancel");

		HorizontalPanel buttonPanel = new HorizontalPanel();
		buttonPanel.setSpacing(15);
		buttonPanel.add(saveButton);
		buttonPanel.add(cancelButton);

		flexTable.setWidget(0, 1, titleLabel);
		flexTable.setWidget(1, 0, nameLabel);
		flexTable.setWidget(1, 1, nameBox);
		flexTable.setWidget(2, 0, emailLabel);
		flexTable.setWidget(2, 1, emailBox);
		flexTable.setWidget(3, 0, dobLabel);
		flexTable.setWidget(3, 1, dobBox);
		flexTable.setWidget(4, 0, passwordLabel);
		flexTable.setWidget(4, 1, passwordBox);

		flexTable.setWidget(6, 1, buttonPanel);

		DecoratorPanel panel = new DecoratorPanel();
		panel.add(flexTable);

		initWidget(panel);
	}

	public void saveToModel() {
		user.setName(nameBox.getText().trim());
		user.setEmail(emailBox.getText().trim());
	}

	@Override
	public HasClickHandlers getSaveButton() {
		// TODO Auto-generated method stub
		return saveButton;
	}

	@Override
	public HasClickHandlers getCancelButton() {
		// TODO Auto-generated method stub
		return cancelButton;
	}

	@Override
	public Widget asWidget() {
		// TODO Auto-generated method stub
		return this;
	}

}
